import paddlex as pdx
from paddlex import transforms as T

'''
paddleX 中的图像处理集合模块，是一个列表
用来放置图片的各种操作

Resize 统一将图片 ReSize 成一样的尺寸

RandomHorizontalFlip 对图像进行随机概率的翻转

Normalize 图像的标准化
    - mean:list 图像数据集的均值
    - std:list 图像的标准差
'''
train_transforms = T.Compose([
    T.Resize(target_size=[590,1640]),
    T.RandomHorizontalFlip(),
    T.Normalize(
        mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
])

eval_transforms = T.Compose([
    T.Resize(target_size=[590,1640]),
    T.Normalize(
        mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
])

train_dataset = pdx.datasets.SegDataset(
    data_dir='/media/string/My' + ' Passport/CULane/CULane',
    file_list='/media/string/My' + ' Passport/CULane/CULane/train_img_list.txt',
    label_list='/media/string/My' + ' Passport/CULane/CULane/labels.txt',
    transforms=train_transforms,
    shuffle=True)

eval_dataset = pdx.datasets.SegDataset(
    data_dir='/media/string/My' + ' Passport/CULane/CULane',
    file_list='/media/string/My' + ' Passport/CULane/CULane/eval_img_list.txt',
    label_list='/media/string/My' + ' Passport/CULane/CULane/labels.txt',
    transforms=eval_transforms,
    shuffle=False)

num_classes = len(train_dataset.labels)
model = pdx.seg.DeepLabV3P(num_classes=num_classes, backbone='ResNet50_vd')

model.train(
    num_epochs=10,
    train_dataset=train_dataset,
    train_batch_size=1,
    eval_dataset=eval_dataset,
    learning_rate=0.01,
    save_dir='output/deeplabv3p_r50vd',
    log_interval_steps=1,
    )